<!-- 我的 -->
<template>
	<zh-app style="background-color: white;font-family: '阿里巴巴普惠体'">
		<!-- 导航栏 -->
		<zh-navbar title="我的" color="#85a5ff" linear="right" :hideHome="true" />
		<!-- 个人信息栏 -->
		<zh-sheet>
			<view class="flex-row-center-start">
			<!-- 头像 -->
			<zh-avatar :size="130" outlined :round="20" :img="data.userInfo.photoPath"></zh-avatar>
			<view style="padding-left:20rpx">
				<!-- 姓名性别 -->
				<view class="flex-row-center-start">
					<zh-text :fontSize="32" :label="data.hiddenFlag?enName():data.userInfo.fullName"></zh-text>
					<zh-tag :fontSize="32" :followTheme="false" :color="data.userInfo.sex==='2'?'#FF557F':'#429BED'" size="m" :round="24" :label="data.userInfo.sex=='2'?'女':'男'"></zh-tag>
					<tm-icon :name="!data.hiddenFlag?'tmicon-eye':'tmicon-eye-slash'" :fontSize="40" @tap="changePrivacy"></tm-icon>
				</view>
				<!-- 身份证 -->
				<zh-text  :fontSize="32" :label="data.hiddenFlag?enCard():data.userInfo.idcard"></zh-text>
			</view>
			</view>
		</zh-sheet>
		<!-- 菜单项 -->
		<view class="menu-item flex-left" @tap="gotoDetail(item.route)" v-for="(item, index) in data.menuArr" :key="index">
			<tm-icon :name="item.icon" :fontSize="36" style="margin-right: 12rpx;"></tm-icon>
			<zh-text :label="item.name" :fontSize="32"></zh-text>
		</view>
		
		<view class="menu-item flex-left" @tap="familyGoto()" v-for="(item, index) in data.menuArr2" :key="index">
			<tm-icon :name="item.icon" :fontSize="36" style="margin-right: 12rpx;"></tm-icon>
			<zh-text :label="item.name" :fontSize="32"></zh-text>
		</view>
		
		<zlb-footer></zlb-footer>
	</zh-app>
</template>
<script lang="ts" setup>
	import { ref, reactive } from "vue";
	import { onLoad } from "@dcloudio/uni-app";
	import { user } from '@/store';
	import systemConfig from '@/common/config';
	// ------------------接收传入参数(组件)-------------------

	// ------------------钩子函数----------------------------
	// 初始化
	onLoad(() => {
		getMenuArr();		 
	})

	// ------------------变量区------------------------------
	// 路由对象
	// 主数据
	const data = reactive({
		// 是否脱敏标记
		hiddenFlag: true,
		// 个人信息
		userInfo: {
			fullName: user.fullName||"测试",
			sex: user.userInfo?.sex||'1',
			idcard: user.userInfo?.idcard||"00000000000000",
			photoPath:(user.userInfo?.photoPath?user.userInfo.photoPath:(user.userInfo?.sex==='2'?'/static/user/avatar_gril.png':'/static/user/avatar_boy.png'))
		},
		// 菜单项数组
		menuArr: [
			{
				name: '房产使用',
				icon: 'tmicon-home',
				route: '/pages/edu/myHouse/myHouse'
			},{
				name: '当年适龄子女',
				icon: 'tmicon-md-people',
				route: '/pages/edu/theRightChild/theRightChild'
			},{
				name: '我的报名',
				icon: 'tmicon-ios-filing',
				route: '/pages/edu/enroll/myEnroll'
			},{
				name: '我的申诉',
				icon: 'tmicon-structured-data',
				route: '/pages/edu/appeal/myAppeal'
			},{
				name: '我的申请记录',
				icon: 'tmicon-paperplane-fill',
				route: '/pages/edu/myApply/myApply'
			},{
				name: '系统设置',
				icon: 'tmicon-resource',
				route: '/pages/edu/sysSettings/sysSettings'
			}
		],
		menuArr2: [
			{
				name: '我的家庭码',
				icon: 'tmicon-home'
			}
		],
		// 姓名脱敏状态
		privacyName: true,
		// 身份证脱敏状态
		privacyIdcard: true
	})

	// ------------------方法区------------------------------
	// 获取菜单项数组
	const getMenuArr = () => {
		
	}
	// 切换并获取脱敏/正常数据
	const changePrivacy=()=>{
		data.hiddenFlag=!data.hiddenFlag
	}
	const enName=()=>{
		let fullName = data.userInfo.fullName
		if(!fullName){
			return '';
		}
		return '*'+fullName.substring(1,fullName.length)
	}
	const enCard=()=> {
		let idCard = data.userInfo.idcard
		if(!idCard){
			return '';
		}
		let enCard = ""
		if (idCard.length===18) {
			enCard = idCard.replace(/(\w{1})\w*(\w{1})/, '$1****************$2');
		}else{
			let len=idCard.length/3
			let baseLen=idCard.length-len*2
			enCard=idCard.substring(0, len)
					
			for(var i=0;i<baseLen;i++){
				enCard=enCard+"*"
			}
			enCard=enCard+idCard.substring(len*2, idCard.length)
		}
		return enCard
	}
	// 跳转至目标详情页
	const gotoDetail = (path: string) => {
		$router.push(path,{})
	}
	
	//我的家庭码
	//浙里办回调地址
	let gotourl = window.location.href+'?params=';
	const familyGoto=()=>{
		 console.log('gotourl：'+gotourl);		
		const params: any =  {
		tokenId: systemConfig.familyTokenId,
		goto: gotourl,
		choose: '1'
		}	
			
		ZWJSBridge.openLink({
		//自定义参数
		//正式
		// url: `https://mapi.zjzwfw.gov.cn/web/mgop/gov-open/zj/2001907955/reserved/index.html#/familyProvide/${encodeURIComponent(JSON.stringify(params))}` 
		url: systemConfig.familyUrl+`${encodeURIComponent(JSON.stringify(params))}`		 
		
		}).then((res:any) => {
		console.log('正式返回：'+res);
		}).catch((error:any)  => console.log('错误信息正式：'+error))
	}
	
</script>
<style lang="scss" scoped>
	.menu-item {
		height: 100rpx;
		margin: 0 60rpx;
	}
</style>
